<script setup lang="ts">
import { ref } from "vue";
import { ElMessage } from "element-plus";
import { userChangePassword } from "@/api/user";

defineOptions({
  name: "Welcome"
});
const old_password = ref("");
const new_password = ref("");
const confirm_password = ref("");
const submit = () => {
  if (new_password.value != confirm_password.value) {
    console.log("密码错误");
    ElMessage.error("密码不一致");
    return;
  }
  const submit_body = {
    id: 1,
    oldPassword: old_password.value,
    newPassword: new_password.value
  };
  userChangePassword(submit_body)
    .then(ret => {
      if (ret["code"] != 0) {
        ElMessage.error(ret["detail"]);
        return;
      }
      ElMessage.success("密码修改成功");
    })
    .catch(error => {
      console.log(error);
      ElMessage.error("服务器异常");
    });
};
// const aaa = ref(1);
// const bbb = ref("");
// const ccc = ref(4);
// const ddd = ref(0);
// const eee = ref([1252, "122199", { jjj: 452, ujuj: "uyu" }]);
// const fff = ref({ a: 123, b: [789456], c: "qwer" });
// const measure = () => {
//   console.log(fff.value["b"]);
//   // for (let i = 0; i < eee.value.length; i++) {
//   //   console.log(eee.value[i]);
//   // }
// };
// const fangfa = () => {
//   console.log(bbb.value);
//   ccc.value++;
//   let svm = 0;
//   for (let i = 1; i <= ccc.value; i++) {
//     svm += i;
//   }
//   ddd.value = svm;
//   if (aaa.value == 1) {
//     aaa.value = 2;
//   } else {
//     aaa.value = 1;
//   }
// };
</script>

<template>
  <div>
    <h1>修改密码</h1>
    <!-- <el-button type="primary" @click="measure"> 666 </el-button>
    <el-button type="primary" @click="fangfa"> {{ aaa }} </el-button>
    <el-input v-model="bbb" style="width: 240px" placeholder="Please input" />
    {{ ddd }}
    <el-row :gutter="6">
      <el-col :span="8">1</el-col>
      <el-col :span="8">1</el-col>
      <el-col :span="8">1</el-col>
    </el-row> -->
    <el-input
      v-model="old_password"
      style="width: 240px"
      placeholder="旧密码"
    />
    <el-input
      v-model="new_password"
      style="width: 240px"
      placeholder="新密码"
    />
    <el-input
      v-model="confirm_password"
      style="width: 240px"
      placeholder="确认密码"
    />
    <el-button type="success" @click="submit">确认提交</el-button>
  </div>
</template>
